<template>
  <el-aside width="200px" class="sidebar-container">
    <el-scrollbar class="sidebar-scrollbar">
      <el-menu
        :default-active="activeMenu"
        :router="true"
        class="sidebar-menu"
      >
        <!-- 主要导航 -->
        <el-menu-item index="/">
          <el-icon><HomeFilled /></el-icon>
          <template #title>首页</template>
        </el-menu-item>
        <el-menu-item index="/trending">
          <el-icon><TrendCharts /></el-icon>
          <template #title>热门视频</template>
        </el-menu-item>
        <el-menu-item index="/community">
          <el-icon><ChatLineRound /></el-icon>
          <template #title>社区</template>
        </el-menu-item>
        
        <el-divider />

        <!-- 用户相关 - 改为子菜单 -->
        <el-sub-menu index="/user">
          <template #title>
            <el-icon><UserFilled /></el-icon>
            <span>个人资料</span>
          </template>
          <el-menu-item index="/user/videos">
            <el-icon><VideoCameraFilled /></el-icon>
            <template #title>我的视频</template>
          </el-menu-item>
          <el-menu-item index="/user/posts">
            <el-icon><Document /></el-icon>
            <template #title>我的帖子</template>
          </el-menu-item>
          <el-menu-item index="/user/subscriptions">
            <el-icon><StarFilled /></el-icon>
            <template #title>我的订阅</template>
          </el-menu-item>
          <el-menu-item index="/user/settings">
            <el-icon><Setting /></el-icon>
            <template #title>账号设置</template>
          </el-menu-item>
        </el-sub-menu>

        <!-- 分隔线 -->
        <el-divider />

        <!-- 探索 -->
        <el-sub-menu index="explore">
          <template #title>
            <el-icon><Compass /></el-icon>
            <span>探索</span>
          </template>
          <el-menu-item index="/category/music">
            <el-icon><Headset /></el-icon>
            <template #title>音乐</template>
          </el-menu-item>
          <el-menu-item index="/category/gaming">
            <el-icon><Trophy /></el-icon>
            <template #title>游戏</template>
          </el-menu-item>
          <el-menu-item index="/category/education">
            <el-icon><Reading /></el-icon>
            <template #title>教育</template>
          </el-menu-item>
          <el-menu-item index="/category/tech">
            <el-icon><Monitor /></el-icon>
            <template #title>科技</template>
          </el-menu-item>
          <el-menu-item index="/category/lifestyle">
            <el-icon><House /></el-icon>
            <template #title>生活</template>
          </el-menu-item>
          <el-menu-item index="/category/movies">
            <el-icon><Film /></el-icon>
            <template #title>电影</template>
          </el-menu-item>
          <el-menu-item index="/category/anime">
            <el-icon><PictureFilled /></el-icon>
            <template #title>动漫</template>
          </el-menu-item>
          <el-menu-item index="/category/sports">
            <el-icon><Football /></el-icon>
            <template #title>体育</template>
          </el-menu-item>
          <el-menu-item index="/category/comedy">
            <el-icon><Sunny /></el-icon>
            <template #title>搞笑</template>
          </el-menu-item>
          <el-menu-item index="/category/other">
            <el-icon><More /></el-icon>
            <template #title>其他</template>
          </el-menu-item>
        </el-sub-menu>

      </el-menu>
    </el-scrollbar>
  </el-aside>
</template>

<script setup>
import { computed, h } from 'vue'
import { useRoute } from 'vue-router'
import { useStore } from 'vuex'
import {
  HomeFilled,
  VideoCameraFilled,
  // Collection, // 这个可以移除了，如果 StarFilled 替代了
  UserFilled, // 确保已导入
  Clock,
  Grid,
  Watch,
  StarFilled, // 确保已导入
  TrendCharts,
  Headset,
  Trophy,
  Document, // 确保已导入
  Football,
  Reading,
  Brush,
  Film,
  Opportunity,
  ChatLineRound,
  Compass, // 确保已导入
  House, // 确保已导入
  Monitor, // 确保已导入
  PictureFilled, // 确保已导入
  Sunny, // 确保已导入
  More, // 确保已导入
  Setting // 确保已导入
} from '@element-plus/icons-vue'

const store = useStore()
const route = useRoute()

const isAuthenticated = computed(() => store.getters['auth/isAuthenticated'])

const activeMenu = computed(() => {
  const { meta, path } = route
  // 如果路由元信息指定了 activeMenu，则使用它
  if (meta.activeMenu) {
    return meta.activeMenu
  }
  // 对于 /user/ 下的子路由，如果 meta.activeMenu 未设置，则默认高亮 /user
  if (path.startsWith('/user/')) {
    return '/user'
  }
  // 确保返回的路径与路由配置完全匹配
  return path === '/' ? path : path.replace(/\/$/, '')
})

const WatchIconComponent = {
  name: 'WatchIcon',
  render() {
    return h(Clock)
  }
}
</script>

<style scoped>
.sidebar-container {
  transition: width 0.28s;
  height: calc(100vh - 56px);
  position: fixed;
  top: 56px;
  left: 0;
  bottom: 0;
  z-index: 1001;
  background-color: #ffffff; /* 修改为纯白背景 */
  overflow: hidden;
  width: 200px;
  box-shadow: 1px 0 4px rgba(0, 0, 0, 0.08); /* 调整阴影效果 */
}

.sidebar-scrollbar {
  height: 100%;
}

.sidebar-scrollbar :deep(.el-scrollbar__bar) {
  width: 12px;
}

.sidebar-scrollbar :deep(.el-scrollbar__bar.is-horizontal) {
  display: none;
}

.sidebar-scrollbar :deep(.el-scrollbar__bar.is-vertical) {
  right: 2px;
}

.sidebar-scrollbar :deep(.el-scrollbar__thumb) {
  background-color: #909399;
  border-radius: 6px;
}

.sidebar-scrollbar :deep(.el-scrollbar__thumb:hover) {
  background-color: #606266;
}

.sidebar-scrollbar :deep(.el-scrollbar__track.is-vertical) {
  background-color: #f5f7fa;
  border-radius: 6px;
}

.sidebar-menu {
  border-right: none;
  padding: 16px 0; /* 调整内边距 */
}

:deep(.el-sub-menu__title) {
  height: 48px; /* 增加高度 */
  line-height: 48px;
  font-size: 14px;
  color: #303133;
  padding: 0 16px !important; /* 统一内边距 */
}

:deep(.el-sub-menu__title .el-icon) {
  margin-right: 12px;
  width: 20px;
  text-align: center;
  font-size: 18px;
}

:deep(.el-sub-menu__title:hover) {
  background-color: #f5f7fa;
}

:deep(.el-menu--inline) {
  background-color: #f9f9f9;
  padding: 4px 0;
}

.el-menu-item {
  height: 48px; /* 增加高度 */
  line-height: 48px;
  font-size: 14px;
  color: #606266;
  padding: 0 16px !important; /* 统一内边距 */
}

.el-menu-item .el-icon {
  margin-right: 12px;
  width: 20px;
  text-align: center;
  font-size: 18px;
  display: inline-flex; /* 修改为 inline-flex */
  align-items: center;
  justify-content: center;
}

.el-menu-item:hover {
  background-color: #f5f7fa;
}

.el-menu-item.is-active {
  background-color: #e6f4ff; /* 更柔和的激活背景色 */
  color: #1890ff;
  font-weight: 500;
}

.el-divider {
  margin: 8px 0;
  background-color: #f0f0f0;
}

/* 响应式处理 */
@media (max-width: 768px) {
  .sidebar-container {
    transform: translateX(-200px);
  }
}
</style>

